package com.xianyun.site.iblog.user.executor.command;

import com.alibaba.cola.dto.Response;
import com.xianyun.site.iblog.convertor.SocialUserConvertor;
import com.xianyun.site.iblog.domain.user.gateway.SocialUserGateway;
import com.xianyun.site.iblog.dto.user.SocialUserAddCmd;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 三方用户保存
 * @author mac_zyj
 */
@Slf4j
@Component
public class SocialUserAddCmdExo {

    @Autowired
    private SocialUserGateway socialUserGateway;

    public Response  execute(SocialUserAddCmd cmd){
        try {
            socialUserGateway.checkAndInsertAuthToken(SocialUserConvertor.toEntity(cmd.getSocialUserDTO()));
            return Response.buildSuccess();
        }
        catch (Exception ex){
            return Response.buildFailure("BIZ_SOCIAL_SAVE_ERROR","保存失败");
        }
    }
}
